﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ConnectionManager : MonoBehaviour
{
    public int port = 378;

    private bool connected = false;

    public List<NetworkPlayer> clients = new List<NetworkPlayer>();

    #region Unity Events

    // Use this for initialization
    void Start()
    {
        print("Connection manager started");
        DontDestroyOnLoad(this.gameObject);

    }

    // Update is called once per frame
    void Update()
    {

    }

    #endregion

    #region Server

    void OnPlayerConnected(NetworkPlayer player)
    {
        if (!clients.Contains(player))
        {
            clients.Add(player);
        }
        print("Player connected, apparently");
    }

    public void InitializeServer(int numConnections)
    {
        Network.InitializeServer(numConnections, port, false);
    }

    void OnServerInitialized()
    {
        print("Server initialized");
    }

    void OnGUI()
    {
        if (connected)
        {
            GUILayout.Label("Connected");
        }
    }

    public void RunServer(int numConnections)
    {
        InitializeServer(numConnections);
    }

    #endregion

    #region Client

    void OnConnectedToServer()
    {
        connected = true;
    }

    public void RunClient()
    {
    }

    #endregion

}
